<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-01 12:57:40
 * @Last Modified time: 2023-02-23 11:06:29
 */
namespace app\common\dao\store;

use frank\base\BaseDao;
use app\common\model\store\OrderModel;

/**
 * Class OrderDao
 * @package app\common\dao\store
 */
class OrderDao extends BaseDao
{
    /**
     * 设置模型名
     */
    protected function setModel(): string
    {
        return OrderModel::class;
    }

    /**
     * 列表
     */
    public function getOrderList(?array $where = [], int $page, int $limit, ?array $field = [], ?array $with = [])
    {
        return $this->search($where)->with($with)->field($field ?? ['*'])->order('id DESC')->page($page)->paginate($limit);
    }

    /**
     *  订单详情
     * @param $orderNo
     */
    public function getOrderPayDetail($orderNo)
    {
        return $this->search([])->with(['user_detail','address','goods'])->where(['order_no' => $orderNo, 'pay_status' => 0, 'delete_time' => 0], ['goods', 'user_detail'])->find();
    }


    /**
     * 生成订单号
     */
    public function orderNo()
    {
        return date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);
    }

}
